//
//  AXFNearShopTableViewCell.m
//  MineOrderUI
//
//  Created by mac2 on 16/11/20.
//  Copyright © 2016年 mac2. All rights reserved.
//

#import "AXFNearShopTableViewCell.h"
#import "Masonry.h"
#import "CZAdditions.h"
@implementation AXFNearShopTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setupUI];
        [self loadJson];
    }
    return self;
}

-(void)loadJson{
    
}

-(void)collectShop:(UIButton *)sender{
    
    sender.selected = YES;
    sender.backgroundColor = [UIColor grayColor];
}

-(void)setupUI{
//    self.contentView.backgroundColor = [UIColor grayColor];

    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    UILabel *shopNameLabel = [[UILabel alloc]init];
    shopNameLabel.font = [UIFont systemFontOfSize:14];
    shopNameLabel.backgroundColor = [UIColor redColor];
    shopNameLabel.text = @"店名";
    
    UILabel *timeLabel = [[UILabel alloc]init];
    timeLabel.font = [UIFont systemFontOfSize:11];
    timeLabel.backgroundColor = [UIColor redColor];
    timeLabel.text = @"时间";
    
    UILabel *adressLabel = [[UILabel alloc]init];
    adressLabel.font = [UIFont systemFontOfSize:11];
    adressLabel.numberOfLines = 2;
    adressLabel.backgroundColor = [UIColor redColor];
    adressLabel.text = @"地址";
    
    UILabel *distanceLabel = [[UILabel alloc]init];
    distanceLabel.font = [UIFont systemFontOfSize:10];
    distanceLabel.backgroundColor = [UIColor redColor];
    distanceLabel.text = @"距离";
    distanceLabel.textAlignment = NSTextAlignmentRight;
    
    UIButton * collectionBtn = [[UIButton alloc]init];
    [collectionBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
    collectionBtn.backgroundColor = [UIColor cz_colorWithHex:0xffd700];
//    [collectionBtn setTitle:@"已收藏" forState:UIControlStateSelected];
//    [collectionBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
//    collectionBtn.titleLabel.text = @"+收藏";
    [collectionBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [collectionBtn setTitle:@"+收藏" forState:UIControlStateNormal];
//按钮选中状态样式
    [collectionBtn setTitle:@"已收藏" forState:UIControlStateSelected];
    [collectionBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    
//给按钮添加点击事件
    [collectionBtn addTarget:self action:@selector(collectShop:) forControlEvents:UIControlEventTouchUpInside];

//按钮的圆角切割
    [collectionBtn.layer setMasksToBounds:YES];
    [collectionBtn.layer setCornerRadius:6];
    
    
    //添加
    [self.contentView addSubview:shopNameLabel];
    [self.contentView addSubview:timeLabel];
    [self.contentView addSubview:adressLabel];
    [self.contentView addSubview:distanceLabel];
    [self.contentView addSubview:collectionBtn];
    
    //约束
    [distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).mas_offset(@30);
        make.right.mas_equalTo(self.contentView).mas_offset(@-21);
        make.width.equalTo(@40);
    }];
    
    [shopNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(23);
        make.left.mas_equalTo(self.contentView).mas_offset(15);
//        make.width.equalTo(@308);
        make.right.mas_equalTo(distanceLabel.mas_left).offset(-28);
    }];
    
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).offset(15);
        make.top.mas_equalTo(shopNameLabel.mas_bottom).offset(12);
//        make.width.equalTo(@200);
        make.right.equalTo(self.contentView).offset(-180);
    }];
    [collectionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.contentView).mas_offset(@-20);
        make.right.mas_equalTo(self.contentView).mas_offset(@-15);
        make.width.equalTo(@70);
    }];
    
    [adressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).offset(15);
//        make.top.mas_equalTo(timeLabel.mas_bottom).offset(8);
//        make.width.equalTo(@308);
        make.bottom.equalTo(self.contentView).offset(-22);
        make.right.equalTo(self.contentView).offset(-88);
        
    }];
    
    
    
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
